package com.cwn.wizbank.controller.admin;

import com.cw.wizbank.config.WizbiniLoader;
import com.cw.wizbank.qdb.loginProfile;
import com.cwn.wizbank.services.MonitorService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

//对接监管平台
@Controller("adminMonitorController")
@RequestMapping("admin/monitor")
public class MonitorController {

    public static final Logger logger = Logger.getLogger("RegulatoryPlatform");
    @Autowired
    MonitorService monitorService;

    /**
     *监管系统学员导入导出页面
     */
    @RequestMapping(value = "/index")
    public String index() {
        return "admin/monitor/index";
    }

    /**
     *导入监管学员，更新身份证号
     */
    @RequestMapping(value = "importMonitor",method = RequestMethod.POST)
    public String importMonitor(WizbiniLoader wizbini, RedirectAttributes ra, @RequestParam(required = false) MultipartFile uploadFile, loginProfile prof, ModelAndView mav, @RequestParam(required = false) String upload){
        String fileName=uploadFile.getOriginalFilename();
        long size=uploadFile.getSize();
        if(StringUtils.isEmpty(fileName)||size==0){
            ra.addFlashAttribute("code","201");
            ra.addFlashAttribute("message","文件为空，请重新上传！");
        }
        monitorService.importMonitor(uploadFile,wizbini,prof,ra,fileName);
        return "redirect:/app/admin/monitor/index";
    }
}
